package com.gf.support.gateway.config.react;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.annotation.Order;
import org.springframework.http.client.reactive.ReactorResourceFactory;

/**
 * Netty相关优化配置
 */
@Configuration
@PropertySource("classpath:netty-reactor.properties")
@Order(-1)
@Data
public class ReactNettyConfiguration {

    @Value("${reactor.netty.http.server.accessLogEnabled}")
    private String accessLog;

    @Value("${reactor.netty.workerCount}")
    private String workerCount;

    @Bean
    @Order(-1)
    @ConditionalOnMissingBean
    public ReactorResourceFactory reactorClientResourceFactory() {
        System.setProperty("reactor.netty.http.server.accessLogEnabled", accessLog);
        System.setProperty("reactor.netty.ioWorkerCount", workerCount);
        return new ReactorResourceFactory();
    }
}
